package com.jbinfo.qingcaowan.util;

import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.junit.Ignore;
import org.junit.Test;

import com.jbinfo.common.utils.UUIDUtils;
import com.jbinfo.qingcaowan.wx.WxInfo;
import com.jbinfo.qingcaowan.wx.WxLogin;
import com.jbinfo.qingcaowan.wx.WxUserInfo;

public class Util {
	
	@Ignore
	@Test
	public void testInt() {
		Integer inNum = Integer.valueOf("2.23");
		String[] str = inNum.toString().split(".");
		int nNum = Integer.valueOf(str[0]).intValue();
		System.out.println(nNum);
	}
	@Ignore
	@Test
	public void testUUID() {
		String id = UUIDUtils.create();
		System.out.println("id: " + id);
	}
	@Ignore
	@Test
	public void testArrayToList() {
		String [] s = {"A"};
		List<String> strList = Arrays.asList(s);
		System.out.println("List: " + strList);
		
		List<String> strAList = new ArrayList<String>();
		strAList.add("A");
		strAList.add("C");
		
		boolean bSame = CollectionUtils.isEqualCollection(strList, strAList);
		System.out.println("是否含有相同元素：" + bSame);
		
	}
	@Ignore
	@Test
	public void testRate() {
		int num1 = 2;
		int num2 = 7;
		// 创建一个数值格式化对象

		NumberFormat numberFormat = NumberFormat.getInstance();

		// 设置精确到小数点后2位

		numberFormat.setMaximumFractionDigits(2);

		String result = numberFormat.format((float)num1/(float)num2);
		
		double nRate = (float)num1/(float)num2;
		
		BigDecimal   b   =   new   BigDecimal(nRate); 
		double   f1   =   b.setScale(2,   BigDecimal.ROUND_HALF_UP).doubleValue();  
		
		System.out.println("百分比："+ result + ", 百分率：" + f1);
	}
	@Ignore
	@Test
	public void getWxUserInfo() {
		String code = "011UD85123GBK31oXc412vg8512UD85a";
		WxInfo wxInfo = new WxInfo();
		wxInfo.setCode(code);
		try {
			WxLogin wxLogin = new WxLogin();
			WxInfo wxDTO = wxLogin.getTokenAndOpenId(wxInfo);
			System.out.println("WxDTO: " + wxDTO.toString());
			
//			WxInfo wxDTO = new WxInfo();
//			wxDTO.setAccess_token("9vZ8BWy3HBUWiMoBqMI9y8-sFso10QFVwQ-VZBsR1ANKVvtVElE_FFqAAwZCz_d5RJkp-sa0RNbgKEuyO15_AvkQORL-YAnrNLcWHclJm-g");
//			wxDTO.setOpenId("oBLTJwJYzDOM60uoe3tGCLLHLPu8");
			WxUserInfo wxUserDTO = wxLogin.getUserInfo(wxDTO);
			System.out.println("wxUserDTO: " + wxUserDTO.toString());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			System.out.println("err: " + e.getMessage());
		}
	}
	
	@Test
	public void testMath() {
		
		double dTotalTime = 0.5833;
		dTotalTime = Math.ceil(dTotalTime);
		//Integer nTolTime = Integer.valueOf(String.valueOf(dTotalTime));
		int nTime = (int)dTotalTime;
		System.out.println(nTime);
	}
}
